import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_shop/cons/global_cons.dart';
import 'package:flutter_shop/pages/home/home_router.dart';
import 'package:flutter_shop/pages/home/home_tab_page/entity/home_content_data.dart';
import 'package:flutter_shop/res/colors.dart';
import 'package:flutter_shop/res/dimens.dart';
import 'package:flutter_shop/res/styles.dart';
import 'package:flutter_shop/routers/navigator_utils.dart';
import 'package:flutter_shop/widget/load_image.dart';

///商品推荐
class GoodsRecommend extends StatelessWidget {
  final List<HomeContentDataRecommand> recommends;

  GoodsRecommend({Key key, this.recommends}) : super(key: key);

  ///标题bar
  Widget _titleBar() {
    return Container(
      alignment: Alignment.centerLeft,
      padding: Paddings.common,
      decoration: BoxDecoration(
        color: Colors.white,
        border: Borders.bottom,
      ),
      child: Text(
        "商品推荐",
        style: TextStyle(color: CommonColors.primary, fontSize: CommonDimens.font_size_middle),
      ),
    );
  }

  //商品列表
  Widget _goodsList() {
    return Container(
      height: ScreenUtil().setHeight(333),
      child: ListView.builder(
        scrollDirection: Axis.horizontal,
        itemCount: recommends.length,
        itemBuilder: _buildItem,
      ),
    );
  }

  Widget _buildItem(context, index) {
    HomeContentDataRecommand item = recommends[index];
    return Container(
      width: ScreenUtil().setWidth(250),
      height: ScreenUtil().setHeight(333),
      padding: EdgeInsets.only(bottom: 10),
      decoration: BoxDecoration(
        color: Colors.white,
        border: Borders.right,
      ),
      child: InkWell(
        onTap: () {
          NavigatorUtils.push(context, HomeRouter.goodDetail, params: {GlobalCons.KEY_ID: item.goodsId});
        },
        child: Column(
          children: <Widget>[
            Expanded(
              child: LoadImage(item.image),
            ),
            Text(
              "¥${item.mallPrice}",
              style: TextStyles.common_text,
            ),
            Text(
              "¥${item.price}",
              style: TextStyle(
                fontSize: CommonDimens.font_size_small,
                color: CommonColors.gray,
                decoration: TextDecoration.lineThrough,
              ),
            ),
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          _titleBar(),
          _goodsList(),
        ],
      ),
    );
  }
}
